package cz.muni.fi.pa165.musiclibrary.musiclibraryweb.components;

import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.model.Model;

import com.google.common.collect.Sets;

/**
 * Removes specified css class from class attribute.
 * 
 * @author Maros Kucbel
 * @date 2012-11-26T19:05:55+0100
 */
public final class CssClassRemover extends AttributeModifier {
    
    public CssClassRemover(String cssClass) {
        super("class", false, Model.<String>of(cssClass));
    }

    @Override
    protected String newValue(String currentValue, String replacementValue) {
        if (StringUtils.isBlank(currentValue)) {
            return "";
        }
        Set<String> classes = Sets.newHashSet(currentValue.split(" "));
        classes.remove(replacementValue);
        return StringUtils.join(classes, " ");
    }
}